package trlygjj.tanruiliyigenjinjin.web.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import trlygjj.tanruiliyigenjinjin.domain.Employee;
import trlygjj.tanruiliyigenjinjin.domain.Grade;
import trlygjj.tanruiliyigenjinjin.domain.PotentialCustomer;
import trlygjj.tanruiliyigenjinjin.page.PageResult;
import trlygjj.tanruiliyigenjinjin.query.ExaminationQueryObject;
import trlygjj.tanruiliyigenjinjin.service.IEmployeeService;
import trlygjj.tanruiliyigenjinjin.service.IExaminationService;
import trlygjj.tanruiliyigenjinjin.service.IGradeService;
import trlygjj.tanruiliyigenjinjin.util.JsonResult;
import trlygjj.tanruiliyigenjinjin.util.PermissionName;

import java.util.List;

/**
 * Created by user on 2018/7/11.
 */
@Controller
@RequestMapping("examination")
public class ExaminationController {

    @Autowired
    private IExaminationService examinationService;
    @Autowired
    private IEmployeeService employeeService;
    @Autowired
   private IGradeService gradeService;
    /**
     * 提供一个默认不输入后缀,直接可以跳转到具有分页的列表页面
     * @return
     */
    @PermissionName("考试管理首页")
    @RequiresPermissions("examination:index")
    @RequestMapping("")
    public String index(){
        return "examination/list";
    }

    /**
     * 具有分页和高级查询
     * @return
     */
    @PermissionName("考试管理数据列表")
    @RequiresPermissions("examination:list")
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(ExaminationQueryObject qo){
        PageResult result = examinationService.query(qo);
        return result;
    }


    /**
     * 删除
     * @param examinationId 要删除的员工对象id
     * @return 返回JsonResult对象判断是否操作成功
     */
    @PermissionName("考试管理删除")
    @RequiresPermissions("examination:delete")
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long examinationId){
        JsonResult result = new JsonResult();
        try{
            examinationService.deleteByPrimaryKey(examinationId);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     *更新考试学生的信息
     * @param potentialCustomer 要更新的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @PermissionName("考试管理数据更新")
    @RequiresPermissions("examination:update")
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(PotentialCustomer potentialCustomer){
        JsonResult result = new JsonResult();
        try{
            examinationService.updateByPrimaryKey(potentialCustomer);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    @PermissionName("考试管理审核")
    @RequiresPermissions("examination:changeStateById")
    @ResponseBody
    @RequestMapping("changeStateById")
    /**
     * 改变考试结果
     */
    public JsonResult changeStateById(PotentialCustomer potentialCustomer){
        JsonResult result = new JsonResult();
        try {
            examinationService.changeStateById(potentialCustomer);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("审核失败");
        }
        return result;
    }
    @PermissionName("获取处理人")
    @RequiresPermissions("examination:getHander")
    @ResponseBody
    @RequestMapping("getHander")
    /**
     * 获取处理人
     */
    public List<Employee> getHander(){
        return employeeService.selectAll();
    }

    @PermissionName("获取意向班级")
    @RequiresPermissions("examination:getInterestClass")
    @ResponseBody
    @RequestMapping("getInterestClass")

    public List<Grade> getInterestClass(){

        return  gradeService.selectAll();
    }


}
